<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>답글 및 덧글형 게시판 예제</title>
<link rel="stylesheet" type="text/css" href="resources/css/wikimi.css" />
<script type="text/javascript" src="resources/js/util.js"></script>
<script type="text/javascript">
function checkForm(f) {
	var result = true;
	if(isNull(f.memo, document.getElementById("error_memo"), "덧글을 입력하세요!!")) result = false;
	return result;
}
</script>
</head>
<body>
<div id="page">
<h3>글 보기</h3>
<table>
	<tr>
		<th align="center" width="60">제목</th>
		<td>${board.title}</td>
	</tr>
	<tr>
		<th align="center">작성자</th>
		<td>${board.id}</td>
	</tr>
	<tr>
		<th align="center">작성일</th>
		<td><fmt:formatDate value="${board.wdate}" type="both" pattern="yyyy/MM/dd a hh:mm:ss" /></td>
	</tr>
	<tr>
		<th align="center">내용</th>
		<td width="600" height="300" valign="top">${board.content}</td>
	</tr>
</table><br />
<div align="center">
	<input type="button" value="답글" onclick="location.href='board_answer?no=${board.no}&page=${page }'" />&nbsp;
	<c:if test="${board.id == id}">	
		<input type="button" value="편집" onclick="location.href='board_update?no=${board.no}&page=${page }'" />&nbsp;
		<input type="button" value="삭제" onclick="location.href='board_delete?no=${board.no}&page=${page }'" />&nbsp;
	</c:if>
	<input type="button" value="목록" onclick="location.href='list?page=${page}'" />
</div><br />
<c:if test="${not empty replies}">
<h3>덧글 목록</h3>
<table>
	<tr>
		<th width="60" align="center">작성자</th>
		<th align="center">덧글</th>
		<th width="160" align="center">작성일</th>
	</tr>
	<c:forEach items="${replies}" var="reply">
	<tr>
		<td align="center">${reply.id}</td>
		<td>${reply.memo}
			<c:if test="${reply.id == id }">
				&nbsp;<span class="small"><a href="reply_delete?no=${reply.no}&page=${page}&rno=${board.no}">삭제</a></span>
			</c:if>
		</td>
		<td align="center"><fmt:formatDate value="${reply.wdate}" type="both" pattern="yyyy/MM/dd a hh:mm:ss"/></td>
	</tr>
	</c:forEach>
</table><br />
</c:if>
<h3>덧글 쓰기</h3>
<form:form modelAttribute="reply" action="reply_insert" method="post" onsubmit="return checkForm(this)">
<input type="hidden" name="rno" value="${board.no}" />
<input type="hidden" name="page" value="${page}" />
<table>
	<tr>
		<th width="60" align="center">작성자</th>
		<th align="center">덧글</th>
	</tr>
	<tr>
		<td align="center">${id}</td>
		<td><form:input path="memo" name="memo" size="100" htmlEscape="false"/><br />
			<span class="error-text" id="error_memo"></span>
		</td>
	</tr>
</table><br />
<div align="center">
	<input type="submit" value="확인" />
</div>
</form:form>
</div>
</body>
</html>